package com.atguigu.a_properties;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
/*
    Test运行时是进程

    Test是单线程程序 -> 主线程 : main线程
 */
public class Test {
    public static void main(String[] args) throws IOException {
        //获取用户注册的信息
        //创建属性集对象
        Properties properties = new Properties();

        //一键读取
        FileInputStream fis = new FileInputStream("T_Day24\\test\\login.properties");
        properties.load(fis);

        //关流
        fis.close();

        //取出用户组成的账号和密码
        String username = properties.getProperty("username");
        String password = properties.getProperty("password");
        String checkWord = properties.getProperty("checkword");

        //模拟用户登录
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            System.out.println("请您输入账号 : ");
            String uName = sc.nextLine();
            System.out.println("请您输入密码 : ");
            String pwd = sc.nextLine();
            System.out.println("请您输入验证码 : " + checkWord);
            String cWord = sc.nextLine();

            //校验
            if (username.equals(uName) && password.equals(pwd) && checkWord.equalsIgnoreCase(cWord)){
                System.out.println("恭喜您,登录成功 ! ");
                return;
            }else {
                //登录失败且是第三次登录
                if (i == 2){
                    System.out.println("您已经连续三次登录失败 ! 账号被锁定,请联系管理员 ! ");
                    return;
                }
                System.out.println("登录失败 ! 您还剩 " + (2 - i) + " 次机会尝试 ! ");
            }
        }
    }
}
